package activities;

import java.util.concurrent.ExecutionException;

import model.ProductInfoItem;
import pkg.inno.fileshare.R;
import Tasks.GetSpecificProductAsync;
import adapters.GalleryImageAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.VideoView;

public class ProductView extends Activity
{
	TabHost _tabHostObject;
	VideoView _videoView;
	Gallery _gallery;
	ProductInfoItem _prodInfo;
	//ImageSwitcher _switcher;
	ImageView _imgView;
	GalleryImageAdapter _adapter;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		Bundle bundleObj=getIntent().getBundleExtra("productBundle");
		String prodId=bundleObj.getString("productId");
		GetSpecificProductAsync feeder=new GetSpecificProductAsync();
		try {
			_prodInfo=feeder.execute(prodId).get();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		_prodInfo.set_productName(bundleObj.getString("productName"));
		_adapter=new GalleryImageAdapter(this, _prodInfo.get_imageList());
		
		setContentView(R.layout.product_item_view);

		
		_videoView=(VideoView)findViewById(R.id.videoView);
		
		//_switcher=(ImageSwitcher)findViewById(R.id.imgSwitch);
		//_switcher.setFactory(this);
		//_switcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
		//_switcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
		_gallery=(Gallery)findViewById(R.id.imgGallery);
		_gallery.setAdapter(_adapter);
		//_gallery.setOnItemSelectedListener(this);
		
		_tabHostObject=(TabHost)findViewById(R.id.tabHost);
		_tabHostObject.setup();
		
		
		
		/*TabSpec productImageSpec=_tabHostObject.newTabSpec("ProductImages");
		productImageSpec.setIndicator("Product Images");
		Intent productImageIntent=new Intent(ProductView.this,ProductImageView.class);
		productImageSpec.setContent(productImageIntent);
		
		TabSpec productVideoSpec=_tabHostObject.newTabSpec("ProductVideos");
		productVideoSpec.setIndicator("Product Videos");
		Intent productVideoIntent=new Intent(ProductView.this,ProductVideoView.class);
		productVideoSpec.setContent(productVideoIntent);
		
		TabSpec productBrochSpec=_tabHostObject.newTabSpec("ProductBrochures");
		productBrochSpec.setIndicator("Product Brochures");
		Intent productBrocIntent=new Intent(ProductView.this,ProductBrochureView.class);
		productBrochSpec.setContent(productBrocIntent);
		
		_tabHostObject.addTab(productBrochSpec);
		_tabHostObject.addTab(productVideoSpec);
		_tabHostObject.addTab(productImageSpec);*/
		
		TabSpec spec1=_tabHostObject.newTabSpec("Product Image");
        spec1.setContent(R.id.tab1);
        //Intent productImageIntent=new Intent(ProductView.this,ProductImageView.class);
        //spec1.setContent(productImageIntent);
        spec1.setIndicator("Product Image");
      
      
        TabSpec spec2=_tabHostObject.newTabSpec("Product Video");
        spec2.setIndicator("Product Video");
        spec2.setContent(R.id.tab2);
      
      
        TabSpec spec3=_tabHostObject.newTabSpec("Product Brochure");
        spec3.setContent(R.id.tab3);
        spec3.setIndicator("Product Brochure");
        _tabHostObject.addTab(spec1);
        _tabHostObject.addTab(spec2);
        _tabHostObject.addTab(spec3);
	}

}
